package com.nmsl.medicine.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.nmsl.medicine.domain.StorageInDetailRecord;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.medicine.domain.MedicineStorageInRecord;
import com.nmsl.medicine.service.IMedicineStorageInRecordService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 药品入库记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/medicine/record")
public class MedicineStorageInRecordController extends BaseController
{
    @Autowired
    private IMedicineStorageInRecordService medicineStorageInRecordService;

    /**
     * 查询药品入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineStorageInRecord medicineStorageInRecord)
    {
        startPage();
        List<MedicineStorageInRecord> list = medicineStorageInRecordService.selectMedicineStorageInRecordList(medicineStorageInRecord);
        return getDataTable(list);
    }

    /**
     * 导出药品入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:record:export')")
    @Log(title = "药品入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineStorageInRecord medicineStorageInRecord)
    {
        List<MedicineStorageInRecord> list = medicineStorageInRecordService.selectMedicineStorageInRecordList(medicineStorageInRecord);
        ExcelUtil<MedicineStorageInRecord> util = new ExcelUtil<MedicineStorageInRecord>(MedicineStorageInRecord.class);
        util.exportExcel(response, list, "药品入库记录数据");
    }

    /**
     * 获取药品入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:record:query')")
    @GetMapping(value = "/{storageInId}")
    public AjaxResult getInfo(@PathVariable("storageInId") Long storageInId)
    {
        return success(medicineStorageInRecordService.selectMedicineStorageInRecordByStorageInId(storageInId));
    }

    /**
     * 新增药品入库记录
     */
    @PreAuthorize("@ss.hasPermi('medicine:record:add')")
    @Log(title = "药品入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineStorageInRecord medicineStorageInRecord)
    {
        return toAjax(medicineStorageInRecordService.insertMedicineStorageInRecord(medicineStorageInRecord));
    }

    /**
     * 修改药品入库记录
     */
    @PreAuthorize("@ss.hasPermi('medicine:record:edit')")
    @Log(title = "药品入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineStorageInRecord medicineStorageInRecord)
    {
        return toAjax(medicineStorageInRecordService.updateMedicineStorageInRecord(medicineStorageInRecord));
    }

    /**
     * 删除药品入库记录
     */
    @PreAuthorize("@ss.hasPermi('medicine:record:remove')")
    @Log(title = "药品入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storageInIds}")
    public AjaxResult remove(@PathVariable Long[] storageInIds)
    {
        return toAjax(medicineStorageInRecordService.deleteMedicineStorageInRecordByStorageInIds(storageInIds));
    }

    /**
     * 审核
     */
    @PostMapping("/shenhe")
    public AjaxResult shenhe(MedicineStorageInRecord medicineStorageInRecord){


       return toAjax(medicineStorageInRecordService.shenhe(medicineStorageInRecord));
    }

    /**
     * tianjia
     */
    @PostMapping("/tianjia")
    public AjaxResult tianjia(StorageInDetailRecord storageInDetailRecord){
        return toAjax(medicineStorageInRecordService.tianjia(storageInDetailRecord));
    }
}
